package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangyu
 * @data 2023/4/24 17:34
 */
@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation("用户下单接口")
    public Result<OrderSubmitVO> addOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        System.out.println(">>>>>>"+ordersSubmitDTO.getTablewareNumber());
        System.out.println(">>>>>>>>>>"+ordersSubmitDTO.getTablewareStatus());
        return Result.success(orderService.addOrder(ordersSubmitDTO));
    }

    @GetMapping("/historyOrders")
    @ApiOperation("用户查看历史订单接口")
    public Result<PageResult> selectAllOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(orderService.selectAllOrders(ordersPageQueryDTO));

    }

    @PostMapping("/repetition/{id}")
    @ApiOperation("用户再来一单接口")
    public Result<String> getOrderAgain(@PathVariable Long id) {
        orderService.getOrderAgain(id);
        return Result.success();
    }
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("用户查询订单详情接口")
    public Result<OrderVO> selectOrderDetail(@PathVariable Long id){
        return Result.success(orderService.selectOrderDetailByOrderId(id));
    }
    @PutMapping("/cancel/{id}")
    @ApiOperation("用户取消订单")
    public Result<String> cancelOrder(@PathVariable Long id){
        orderService.cancelOrder(id);
        return Result.success();
    }
    @GetMapping("/reminder/{id}")
    @ApiOperation("用户催单接口")
    public Result<String> reminder(@PathVariable Long id){
        orderService.reminder(id);
        return Result.success();
    }


}
